﻿using DanTriNews.Source.DAO;
using Microsoft.Phone.Info;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace DanTriNews.Src.Helper
{
    public class SaveLog
    {
        public async static Task SaveLogInfo()
        {
            DanTriDataContext db = new DanTriDataContext();
            ClientId cid = db.ClientIds.FirstOrDefault();
            if (cid == null)
            {
                cid = new ClientId();
                Random r = new Random();
                cid.Id = r.Next();
                cid.Guid = Guid.NewGuid().ToString();
                db.ClientIds.InsertOnSubmit(cid);
                db.SubmitChanges();
            }
            string name= DeviceStatus.DeviceName;
            string manufacturer = DeviceStatus.DeviceManufacturer;
            string version = DeviceStatus.DeviceFirmwareVersion;
            try
            {
                string url= String.Format("http://myappasha.site88.net/dantri.php?name={0}&manufacturer={1}&version={2}&cid={3}&app={4}", name, manufacturer, version, cid.Guid, "DanTri");
                HttpWebRequest request = HttpWebRequest.Create(new Uri(url)) as HttpWebRequest;
                using (WebResponse response =await request.GetResponseAsync())
                {
                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    {
                        String html = reader.ReadToEnd();
                        reader.Close();
                    }
                    response.Close();
                }

            }
            catch { }
        }
    }
}
